var app = getApp();
var util = require('../../../../utils/util.js');

Page({
    data: { 
        orderId:"",
        systemInfo:{},
        padBtm:"25",
        content:""
    },
    onLoad: function (e) {
        var that = this;
        wx.getSystemInfo({
            success:function(res){ 
              if(res.model == "iPhone X"){
                that.setData({
                    padBtm:"50",
                })
              }
            }
        });
        that.setData({
            navH: app.globalData.navHeight,
            orderId:e.orderId
        });
        that.getTerms();
    },
    navBack: function () {
        wx.navigateBack({
            delta: 1
        })
    },
    orderCancel: function () {
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/order/cancel",
            data: {
                order_id: that.data.orderId,
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
                'Cookie': 'token=' + wx.getStorageSync('token')
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                    var showMsg=res.data.data.msg;
                    wx.showToast({
                        title: showMsg,
                        icon: 'none',
                        duration: 1500
                    });
                    if(res.data.data.flag==1){
                        setTimeout(
                            function(){
                                wx.redirectTo({
                                    url: '../index/order-index'
                                });
                            },2000) 
                    }
                    
                }
            },
            
        });
    },
    getTerms: function () {
        var that = this;
        wx.request({
            url: app.globalData.apiHost + "/api/terms/termsList",
            data: {
                page:1,
                pagesize:1,
                type:1,
            },
            header: {
                'content-type': 'application/x-www-form-urlencoded',
            },
            method: "POST",
            dataType: "json",
            success: function (res) {
                if (res.statusCode === 200) {
                   var contentCode=util.baseDecode(res.data.data.data[0].content);  //base64解码
                   that.setData({
                      content:contentCode
                   })
                }
            },
            
        });
    }
})


